package com.wsyu.springbootbackend.core.util;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private String msg;
    private int code;
    private T data;

    public static Result<String> success() {
        return success(HttpStatus.OK.getReasonPhrase());
    }

    public static <T> Result<T> success(T data) {
        return Result.<T>builder()
                .code(HttpStatus.OK.value())
                .msg(HttpStatus.OK.getReasonPhrase())
                .data(data)
                .build();
    }

    public static Result<String> failure(HttpStatus status) {
        return failure(status, status.getReasonPhrase());
    }

    public static <T> Result<T> failure(HttpStatus status, T data) {
        return Result.<T>builder()
                .code(status.value())
                .msg(status.getReasonPhrase())
                .data(data)
                .build();
    }
}